package com.color.admin.system.entity;


import com.color.admin.common.core.constant.Constant;
import com.color.admin.common.core.constant.ConstantData;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Set;

/**
 * @author HaiQiu
 * @date 2021/12/18
 */
@Entity
@Table(name = ConstantData.MENU_TABLE, schema = ConstantData.SOURCE)
public class SysMenu extends BaseEntity implements Serializable {

    @Schema(description = "主键ID")
    @NotEmpty(message = "ID"+ Constant.NOT_EMPTY,groups = BaseEntity.update.class)
    private String id;

    @Schema(example = "主页", type = "string",description = "菜单权限名称")
    @NotEmpty(message = "名称"+ Constant.NOT_EMPTY)
    @Size(max = 20,message = "名称长度应该在1-20个字符之间")
    private String menuName;

    @Schema(example = "home", type = "string",description = "权限值")
    @Size(max = 20,message = "权限值长度应该在1-20个字符之间")
    private String value;

    @Schema(example = "menu", type = "string",description = "类型：menu菜单，button按钮，iframe嵌套，link外链")
    @Size(max = 10,message = "类型长度应该在1-10个字符之间")
    private String type;

    @Schema(description = "图标")
    @Size(max = 1000,message = "图标地址长度应该在1-1000个字符之间")
    private String icon;

    @Schema(example = "0", type = "string",description = "父级ID,默认0顶级")
    private String parentId;

    @Schema(example = "主页展示效果菜单栏", type = "string",description = "描述")
    @Size(max = 500,message = "描述长度应该在1-1000个字符之间")
    private String description;

    @Schema(example = "/view/user/index.vue",description = "前端视图组件")
    @Size(max = 100,message = "前端视图组件长度应该在1-100个字符之间")
    private String component;

    @Schema(example = "false",description = "是否隐藏菜单，大部分用在无需显示在左侧菜单中的页面，比如详情页")
    private Boolean hidden;

    @Schema(example = "/user",description = "前端路由与接口路径，为菜单时前端路由，为按钮时后端接口，其他为跳转连接")
    @Size(max = 100,message = "路径长度应该在1-100个字符之间")
    private String path;

    @Schema(example = "/test/autocode",description = "高亮左侧菜单的路由地址，比如打开详情页需要高亮列表页的菜单")
    @Size(max = 100,message = "高亮左侧菜单长度应该在1-100个字符之间")
    private String activeUrl;

    @Schema(example = "get",description = "（类型为button时）后端接口请求方法：GET,POST,DELETE,PUT")
    @Size(max = 10,message = "接口请求方法长度应该在1-10个字符之间")
    private String method;

    @Schema(example = "false",description = "是否整页打开路由（脱离框架系），例如：fullpage: true")
    private Boolean fullpage;

    @Schema(example = "false",description = "是否隐藏面包屑")
    private Boolean hiddenBreadcrumb;

    @Schema(example = "/home",description = "重定向地址")
    @Size(max = 500,message = "重定向地址长度应该在1-500个字符之间")
    private String redirect;

    @Schema(description = "绑定角色")
    private Set<SysRole> roles;

    @Id
    @Column(name = "id")
    @GeneratedValue(generator = "id")
    @GenericGenerator(name = "id",strategy="org.hibernate.id.UUIDGenerator")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Basic
    @Column(name = "menu_name")
    public String getMenuName() {
        return menuName;
    }

    public void setMenuName(String menuName) {
        this.menuName = menuName;
    }

    @Basic
    @Column(name = "value")
    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @Basic
    @Column(name = "type")
    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Basic
    @Column(name = "icon")
    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    @Column(name = "parent_id")
    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    @Column(name = "description",length = 500)
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Basic
    @Column(name = "path")
    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    @ManyToMany(mappedBy = "menus")
    public Set<SysRole> getRoles() {
        return roles;
    }

    @JsonIgnore
    public void setRoles(Set<SysRole> roles) {
        this.roles = roles;
    }

    @Basic
    @Column(name = "component")
    public String getComponent() {
        return component;
    }

    public void setComponent(String component) {
        this.component = component;
    }

    @Basic
    @Column(name = "hidden",length = 1)
    public Boolean getHidden() {
        return hidden;
    }

    public void setHidden(Boolean hidden) {
        this.hidden = hidden;
    }

    @Basic
    @Column(name = "method",length = 10)
    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    @Basic
    @Column(name = "full_page",length = 1)
    public Boolean getFullpage() {
        return fullpage;
    }

    public void setFullpage(Boolean fullpage) {
        this.fullpage = fullpage;
    }

    @Basic
    @Column(name = "hidden_breadcrumb",length = 1)
    public Boolean getHiddenBreadcrumb() {
        return hiddenBreadcrumb;
    }

    public void setHiddenBreadcrumb(Boolean hiddenBreadcrumb) {
        this.hiddenBreadcrumb = hiddenBreadcrumb;
    }

    @Basic
    @Column(name = "redirect",length = 500)
    public String getRedirect() {
        return redirect;
    }

    public void setRedirect(String redirect) {
        this.redirect = redirect;
    }

    @Basic
    @Column(name = "active_url",length = 500)
    public String getActiveUrl() {
        return activeUrl;
    }

    public void setActiveUrl(String activeUrl) {
        this.activeUrl = activeUrl;
    }
}
